package com.zzh.api.base.response;

import lombok.Data;

import java.io.Serializable;


/**
 * @author zihong.zheng
 * @version 1.0
 * @date 2019/2/8
 * @time 16:35
 * @description 服务接口响应，统一规范响应
 */
public class BaseResponse implements Serializable {

    private static final long serialVersionUID = -1857233218321357908L;
    public static final int SUCCESS_CODE = 1000;

    public static final String SUCCESS_DESC = "成功";


    public static final int ERROR_CODE = 999;

    public static final String ERROR_DESC = "失败";


    private int respCode;

    private Object data;

    private String respDesc;


    public BaseResponse() {

    }

    public BaseResponse(Object data) {
        this.data = data;
        this.respCode = SUCCESS_CODE;
        this.respDesc = SUCCESS_DESC;
    }


    public BaseResponse setResultSuccess(Object data) {
        return setResult(data, SUCCESS_CODE, SUCCESS_DESC);
    }

    public BaseResponse setResultError(Object data) {
        return setResult(data, ERROR_CODE, ERROR_DESC);
    }


    public BaseResponse setResultSuccess() {
        return setResult(null, SUCCESS_CODE, SUCCESS_DESC);
    }

    public BaseResponse setResult(Object data, int respCode, String respDesc) {
        return new BaseResponse(data, respCode, respDesc);
    }


    public BaseResponse(Object data, int respCode, String respDesc) {
        super();
        this.data = data;
        this.respCode = respCode;
        this.respDesc = respDesc;
    }


    public BaseResponse(int respCode, String respDesc) {
        super();
        this.data = null;
        this.respCode = respCode;
        this.respDesc = respDesc;
    }


    public int getRespCode() {
        return respCode;
    }

    public void setRespCode(int respCode) {
        this.respCode = respCode;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public String getRespDesc() {
        return respDesc;
    }

    public void setRespDesc(String respDesc) {
        this.respDesc = respDesc;
    }

    public static void main(String[] args) {
        BaseResponse baseResponse = new BaseResponse();
        baseResponse.setRespCode(2200);
        baseResponse.setRespDesc("success");
        baseResponse.setData("666");
        System.out.println(baseResponse.toString());

    }

}
